home *** CD-ROM | disk | FTP | other *** search
- /* ---------------------------------------------------------------------------------------------
- Find_icon, code for constructing icon suites for files and folders
-
- by James W. Walker
- preferred e-mail: <mailto:jwwalker@kagi.com>
- alternate e-mail: <mailto:jwwalker@aol.com>, <jim@nisus-soft.com>
- web: <http://users.aol.com/jwwalker/>
-
- File: Get_custom_file_icon.c
-
- Copyright ©1997 by James W. Walker
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours.
- If you're going to re-distribute the source, please make it clear
- that the code was descended from James W. Walker's code,
- but that you've made changes.
- ---------------------------------------------------------------------------------------------
- */
-
- #include <Finder.h>
- #include <Icons.h>
- #include <Resources.h>
- #include <Errors.h>
- #include "Get_custom_file_icon.h"
- #include "cheap-exceptions.h"
- #include "Copy_each_icon.h"
- #include "Get_resource_icons.h"
-
- /* ------------------------------------------------------------------
- Get_custom_file_icon Fill a suite with the custom icon of a
- specified file.
- ------------------------------------------------------------------
- */
- /*
- Custom icons numbered -16496 appear in aliases to volumes and
- servers. I don't know where this is documented.
- */
- #define kVolumeAliasIconResource -16496
-
- OSErr Get_custom_file_icon(
- /* --> */ const FSSpec *filespec,
- /* --> */ MetaSelectorValue icon_selector,
- /* <-- */ Handle *the_suite
- )
- {
- short save_resfile, custom_resfile;
- IconSelectorValue second_selector;
- OSErr err;
-
- ExpandMetaSelector( icon_selector, &icon_selector, &second_selector );
-
- save_resfile = CurResFile();
- SetResLoad( false );
- custom_resfile = FSpOpenResFile( filespec, fsRdPerm );
- SetResLoad( true );
- forbid_action( custom_resfile == -1, FSpOpenResFile,
- err = ResError() );
-
- err = Get1_resource_icons( the_suite, kCustomIconResource, icon_selector );
- if ( (*the_suite == NULL) && (second_selector != 0) )
- {
- err = Get1_resource_icons( the_suite, kCustomIconResource,
- second_selector );
- }
-
- if (err == noMaskFoundErr)
- {
- err = Get1_resource_icons( the_suite, kVolumeAliasIconResource,
- icon_selector );
- if ( (*the_suite == NULL) && (second_selector != 0) )
- {
- err = Get1_resource_icons( the_suite, kVolumeAliasIconResource,
- second_selector );
- }
- }
-
- CloseResFile( custom_resfile );
- UseResFile( save_resfile );
- FSpOpenResFile:
- return err;
- }
-